package cn.com.surker.inspect;

import cn.com.surker.base.BaseEntity;
import cn.com.surker.common.AbstractController;
import cn.com.surker.lab.service.ErpLabExpendBatchService;
import cn.com.surker.lab.service.LabExpendService;
import cn.com.surker.lab.vo.LabExpendBatchVo;
import cn.com.surker.lab.vo.LabExpendVo;
import cn.com.surker.production.entity.ProductionInvoice;
import cn.com.surker.production.service.ProductionInvoiceService;
import cn.com.surker.spring.RestResultDto;
import cn.com.surker.system.model.CacheUser;
import cn.com.surker.util.DateUtil;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * b库消耗
 * </p>
 *
 * @author admin
 * @since 2024-11-05
 */
@RestController("ins-lab-expend-controller")
@RequestMapping("/ins/lab-expend")
public class LabExpendController extends AbstractController {

	@Autowired
	private ProductionInvoiceService invoiceService;
	@Autowired
	private ErpLabExpendBatchService expendBatchService;
	@Value("${erp.datasource.erp.db}")
	private String erpDb;


	@RequestMapping(value = "/invoice/expend/{invoiceId}", method = RequestMethod.POST)
	@ResponseBody
	public RestResultDto invoiceExpendLab(@PathVariable Long invoiceId) {
		if (invoiceId == null) {
			return RestResultDto.fail();
		}
		//	查询发货单数据
		ProductionInvoice invoice = invoiceService.getById(invoiceId);
		if (!BaseEntity.validateExist(invoice)) {
			return RestResultDto.fail("发货单不存在");
		}
		//	查询发货单的盘数据
		List<LabExpendBatchVo> batchList = expendBatchService.queryDetailByInvB(erpDb, invoiceId);
		return RestResultDto.success(batchList);
	}

}



